#!usr/bin/env python
# -*- coding:utf-8 -*-
# user nanme: Mr.zhang
# data time : 2022/11/15   3:53 下午
# project   : read_file.py
# IDE       : PyCharm
# email     :17600960626@163.com

import os



class Corpus:


    def base_path(self,path):
        #获取工作目录绝对路径
        path1 = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        path2=path1 + path
        return path2

    def read_corpus(self,path_name):
        #获取输入效率文件
        files =[]
        for parent, dirnames, filnames in os.walk(path_name):
            for paths in filnames:
                path = os.path.join(paths)
                if '.DS_Store' not in path:
                    L = 'DataLearn'
                    if L in path :
                        files.append(path)
        return files

    def read_fuzed(self,path_name):
        #获取纠错文件
        files =[]
        for parent, dirnames, filnames in os.walk(path_name):
            for paths in filnames:
                path = os.path.join(paths)
                if '.DS_Store' not in path:
                    L = 'fuzzed'
                    if L in path :
                        files.append(path)
        return files

    def read_layout(self,path_name):
        #获取layout文件
        files = []
        path_list = []
        for parent,dirnmaes,filenames in os.walk(path_name):
            for paths in filenames:
                path = os.path.join(paths)
                if '.DS_Store' not in path:
                    L = 'layout'
                    if L in path:
                        files.append(path)
                        path_list.append(path_name+"/"+path)
        a=zip(files,path_list)
        # s=print(dict(a))
        return dict(a)

    def read_log(self,paths):
        # 读取日志TXT
        log_path = []
        for parent, dirnames, filnames in os.walk(paths):
            for paths in filnames:
                path = os.path.join(parent, paths)
                if '.txt' in path:
                    log_path.append(path)
        return log_path